#pragma once
#include "vector.h"

class Player
{
public:
	static const Uint32 COLOR_UNSELECTED = 0x888888;
	static const Uint32 COLOR_SELECTED = 0xffffff;
	Vector size;
	Vector location;
	Vector velocity;
	float speed;
	Uint32 color;

	Player()
	{
		size.set(10, 10);
		location.set(10, 10);
		speed = 20;
		color = COLOR_UNSELECTED;
	}

	bool contains(int a_x, int a_y)
	{
		return a_x >= location.x && a_x < location.x + size.x
			&& a_y >= location.y && a_y < location.y + size.y;
	}

	void draw(SDL_Surface * screen)
	{
		SDL_Rect drawRect = {
			(short)location.x,
			(short)location.y,
			(short)size.x, 
			(short)size.y
		};
		SDL_FillRect(screen, &drawRect, color);	// white player box
	}

	void setColor(int const & c)
	{
		color = c;
	}

	void move(int ms)
	{
		Vector move;
		move.x = velocity.x * ms / 1000;
		move.y = velocity.y * ms / 1000;
		location.x += move.x;
		location.y += move.y;
	}

	void handleInput(SDL_Event e)
	{
		switch(e.key.keysym.sym)
		{
		case SDLK_UP:	velocity.y -= speed;	break;
		case SDLK_DOWN:	velocity.y += speed;	break;
		case SDLK_LEFT:	velocity.x -= speed;	break;
		case SDLK_RIGHT:velocity.x += speed;	break;
		}
	}
};